package com.changgou.listener;

import com.alibaba.fastjson.JSON;
import com.changgou.item.feign.PageFeign;
import entity.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author ：hushengjin
 */

@Component
@RabbitListener(queues = {"topic_queue_spu"})
public class SpuMessageListener {

    @Autowired
    private PageFeign pageFeign;

    @RabbitHandler
    public void spuMessage(String msg) {
        //获取消息,并将消息专程Message
        Message message = JSON.parseObject(msg, Message.class);

        //判断一下是否需要修改
        if (message.getCode() == 2) {
            //修改,调用PageFeign生成静态页
            pageFeign.createHtml(Long.valueOf(message.getContent().toString()));
        }

        if (message.getCode() == 3) {
            //删除
            pageFeign.deleteHtml(Long.valueOf(message.getContent().toString()));
        }
    }

}
